package jdbc;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.sql.*;

/**
 * Created by Administrator on 2017/9/11.
 */
public class ConnsctionTest {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3307/test", "root", "123456");
        if (conn != null) {
            System.out.println("ok");
        } else {
            System.out.println("error");

        }
        Statement statement = conn.createStatement();
        String sql = "select * from tablename2";
        ResultSet set= statement.executeQuery(sql);
        while (set.next()){
            User user=new User();
            user.setId(set.getInt("uid"));
            user.setUsername(set.getString(2));
            user.setPassword(set.getString(3));
            System.out.println(user);

        }
        set.close();
        statement.close();
        conn.close();
    }

}

